﻿using UnityEngine;
using System.Collections;

public class EndControl : MonoBehaviour
{

    public GUIText nowScore;

    public GUIText highScore;

    public GUITexture startButton;

    public static EndControl _instance;

	// Use this for initialization
	void Start ()
	{
	    _instance = this;
	    this.gameObject.SetActive(false);
	}

    public void UpdateScore(int score)
    {
        int highScore = PlayerPrefs.GetInt("score", 0);
        if (score > highScore)
        {
            highScore = score;
            PlayerPrefs.SetInt("score", highScore);
        } 

        this.nowScore.text = score + "";
        this.highScore.text = highScore + "";
        if (Input.GetMouseButtonDown(0) && GameManage._intance.gameState == GameManage.GAME_END)
        {
            Rect rect = startButton.GetScreenRect();
            Vector3 mousePos = Input.mousePosition;

            if (mousePos.x > rect.x && mousePos.x < rect.x + rect.width && mousePos.y > rect.y &&
                mousePos.y < rect.y + rect.height)
            {
                Application.LoadLevel(0);
            }
        }
    }
	
	// Update is called once per frame
	void Update () {
	
	}
}
